package com.advbean;

import com.advbean.config.ScopeConfig;
import com.advbean.music.BlackDisc;
import com.advbean.scope.Notepad;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:com/resource/spring-config.xml"})
//@ContextConfiguration(classes = {ScopeConfig.class, ExpressiveConfig.class})
public class TestClass {

//    private Dessert dessert;
//
//    @Cold
//    @Creamy
//    @Autowired
//    public void setDessert(Dessert dessert) {
//        System.out.println("setDessert()");
//        this.dessert = dessert;
//    }

    @Test
    public void test(){
        AnnotationConfigApplicationContext actx = new AnnotationConfigApplicationContext(ScopeConfig.class);
        for(int i = 3;i>0;i--){
            Notepad notepad = (Notepad) actx.getBean("notepad");
            System.out.println(notepad);;
        }
    }
    @Test
    public void testSpEL(){
//        AnnotationConfigApplicationContext ctx =new AnnotationConfigApplicationContext(ExpressiveConfig.class);
//        BlackDisc disc = (BlackDisc) ctx.getBean("disc");
//        disc.play();

        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:com/resource/spring-config.xml");
        BlackDisc disc = (BlackDisc) ctx.getBean("blackDisc");
        disc.play();
    }
}
